package maf;


import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IBulletSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that CompetitiveRobot's bullets are landed on an enemy.
 * @author Michael Fujimoto
 *
 */

public class TestCompRobotBulletsHit extends RobotTestBed {
  /* True if any bullets were fired in a round, any bullet will be
   * CompetitiveRobot's if challenging SittingDuck
   */
  boolean bulletLanded = false;
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,maf.CompetitiveRobot";
  }

  /**
   * This test runs for 1 round.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * After each turn, check to see if we're at a corner.  If so, set the corresponding flag.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IBulletSnapshot[] allBullets = event.getTurnSnapshot().getBullets();
    int bulletsFired = allBullets.length;
    for (int i = 0;i < bulletsFired;i++) {
      if (allBullets[i].isExplosion()) {
        bulletLanded = true;
      }
    }
  }

  /**
   * After the battle, check to see that a bullet has been landed.
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Bullets Landed", bulletLanded);
  }
}
